package com.创建型模式.工厂模式.抽象工厂模式;


import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;
import org.omg.PortableInterceptor.HOLDING;

import javax.swing.*;
import java.awt.*;

/**
 * 农厂接口
 */
interface Farm{
    /**
     * 生产动物接口
     * @return
     */
    public Animal newAnimal();

    /**
     * 生产植物接口
     * @return
     */
    public Plate newPlate();
}

/**
 * 韶关农场
 */
class SGFarm implements  Farm{
    @Override
    public Animal newAnimal() {
        System.out.println("韶关出产的牛");
        return new Horse();
    }

    @Override
    public Plate newPlate() {
        System.out.println("韶关出产的菜");
        return new Vegetables();
    }
}

/**
 * 上饶农场
 */
class SRFarm implements  Farm{
    @Override
    public Animal newAnimal() {
        System.out.println("上饶马");
        return new Cattle();
    }

    @Override
    public Plate newPlate() {
        System.out.println("上饶果");
        return new Fruit();
    }
}
/**
 * 动物接口
 */
interface Animal{
    public void show();
}

/**
 * 植物接口
 */
interface Plate{
    void show();
}

/**
 * 牛
 */
class Horse implements Animal{
    JScrollPane sp;
    JFrame jf=new JFrame("抽象工厂模式测试");
    public Horse(){
        Container contentPane=jf.getContentPane();
        JPanel p1=new JPanel();
        p1.setLayout(new GridLayout(1,1));
        p1.setBorder(BorderFactory.createTitledBorder("动物：牛"));
        sp=new JScrollPane(p1);
        contentPane.add(sp, BorderLayout.CENTER);
        JLabel l1=new JLabel(new ImageIcon("src/img/A_Horse.jpg"));
        p1.add(l1);
        jf.pack();
        jf.setVisible(false);
        jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//用户点击窗口关闭
    }
    @Override
    public void show() {
        System.out.println("我是牛魔王");
        jf.setVisible(true);
    }
}

/**
 * 马
 */
class Cattle implements Animal{
    JScrollPane sp;
    JFrame jf=new JFrame("抽象工厂模式测试");
    public Cattle(){
        Container contentPane=jf.getContentPane();
        JPanel p1=new JPanel();
        p1.setLayout(new GridLayout(1,1));
        p1.setBorder(BorderFactory.createTitledBorder("动物：牛"));
        sp=new JScrollPane(p1);
        contentPane.add(sp, BorderLayout.CENTER);
        JLabel l1=new JLabel(new ImageIcon("src/img/A_Cattle.jpg"));
        p1.add(l1);
        jf.pack();
        jf.setVisible(false);
        jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//用户点击窗口关闭
    }
    @Override
    public void show() {
        System.out.println("我是白龙马");
        jf.setVisible(true);
    }
}

/**
 * 水果
 */
class Fruit implements Plate{
    JScrollPane sp;
    JFrame jf=new JFrame("抽象工厂模式测试");
    public Fruit()
    {
        Container contentPane=jf.getContentPane();
        JPanel p1=new JPanel();
        p1.setLayout(new GridLayout(1,1));
        p1.setBorder(BorderFactory.createTitledBorder("植物：水果"));
        sp=new JScrollPane(p1);
        contentPane.add(sp, BorderLayout.CENTER);
        JLabel l1=new JLabel(new ImageIcon("src/img/P_Fruitage.jpg"));
        p1.add(l1);
        jf.pack();
        jf.setVisible(false);
        jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//用户点击窗口关闭
    }
    @Override
    public void show() {
        System.out.println("我是火龙果");
        jf.setVisible(true);
    }
}

/**
 * 蔬菜
 */
class Vegetables implements Plate{
    JScrollPane sp;
    JFrame jf=new JFrame("抽象工厂模式测试");
    public Vegetables()
    {
        Container contentPane=jf.getContentPane();
        JPanel p1=new JPanel();
        p1.setLayout(new GridLayout(1,1));
        p1.setBorder(BorderFactory.createTitledBorder("植物：蔬菜"));
        sp=new JScrollPane(p1);
        contentPane.add(sp, BorderLayout.CENTER);
        JLabel l1=new JLabel(new ImageIcon("src/img/P_Vegetables.jpg"));
        p1.add(l1);
        jf.pack();
        jf.setVisible(false);
        jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//用户点击窗口关闭
    }
    @Override
    public void show() {
        System.out.println("我是大波菜");
        jf.setVisible(true);
    }
}



/**
 * 抽象工厂
 */
public class AbstractFactory {
    public static void main(String[] args) {
        Plate frute = new SRFarm().newPlate();
        frute.show();
        Plate vege = new SGFarm().newPlate();
        vege.show();
        Animal ho = new SGFarm().newAnimal();
        ho.show();
        Animal Gattle = new SRFarm().newAnimal();
        Gattle.show();

    }
}
